/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lojavirtual.servlets;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lojavirtual.model.Categoria;
import lojavirtual.persistence.CategoriaDAO;

/**
 *
 * @author 710930
 */
public class CadastrarCategoriaSevlet extends HttpServlet {
   

    private CategoriaDAO categoriaDAO = new CategoriaDAO();
    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        
        Categoria categoria = bindParameters(request);
        categoriaDAO.inserir(categoria);
        RequestDispatcher dispatcher = request.getRequestDispatcher("ListarCategoriaServlet");
        dispatcher.forward(request, response);
        
    }

    public Categoria bindParameters(HttpServletRequest request){
        Categoria categoria = new Categoria();
        categoria.setDescricao(request.getParameter("descricao"));
        categoria.setNome(request.getParameter("nome"));
        return categoria;
    }

}
